// pages/switchingCities/switchingCities.js
//刘丽丽 2019-03-06
var call = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nowcity:'苏州市',
    chooseListBox:[
      {
        firstLetters: "A",
        cityList:[
          { name: '鞍山'},
          { name: '安庆'},
        ]
      }
    ],
    cityWord:'',//城市
    cityView:1,//无数据显示/隐藏(1--有数据，0--无数据)

  },
  //点击选择城市
  chooseCity:function(e){
    console.log(e)
    console.log("我选择的城市id：" + e.currentTarget.dataset.onceid)
    console.log("我选择的城市：" + e.currentTarget.dataset.oncename)
    wx.navigateTo({
      url: '/pages/positioning/positioning',
    })
    wx.setStorageSync('choosename', e.currentTarget.dataset.oncename)
    wx.setStorageSync('chooseid', e.currentTarget.dataset.onceid)

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;  
    
  },
  cityList:function(data){
    var that = this;
    console.log(that)
    if (data.msg == "success"){
      that.setData({
        chooseListBox: data.data,
        cityView: 1,//有数据时显示
      })
    }else{
      // console.log(that.data.cityView)
      that.setData({
        cityView: 0 ,//没有数据的提示
      })
      // console.log(that.data.cityView)
    }
  },
  fail: function () {
    console.log("失败")
  },
  //输入框内城市
  keyword: function (event){
    var that = this
    that.setData({
      cityWord: event.detail.value
    })
  },
  //点击搜索城市
  searchCity:function(){
    var that = this
    var parms = {
      keyWord: that.data.cityWord
    }
    call.getData('city/getCityList', parms, this.cityList, this.fail); //选择城市列表
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this
    var parms = {
      keyWord: that.data.cityWord
    }
    call.getData('city/getCityList', parms, this.cityList, this.fail); //选择城市列表
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})